import { createSlice } from "@reduxjs/toolkit";

//使用createSlice函数创建仓库模块
const counterStore=createSlice({
  name:'counter',
  //初始状态值
  initialState:{
    count:0
  },
  //改变状态值的方法
  reducers:{
    add(state){
      state.count++
    },
    reduce(state){
      state.count--
    },
    changeNum(state,action){
      state.count=action.payload
    }
  }
})
const {add,reduce,changeNum} = counterStore.actions
const countReducer=counterStore.reducer
export {add,reduce,changeNum}
export default countReducer